import "./index.scss";

const toast = (message, type = "success", removeTimeout = 1500) => {
  const body = document.querySelector("body");
  const toast = document.createElement("div");
  toast.classList.add("toast");

  const toastTypes = {
    success: "toast-success",
    error: "toast-error",
    warning: "toast-warning",
    info: "toast-info",
  };

  toastTypes[type] && toast.classList.add(toastTypes[type]);

  toast.innerText = message;
  body.appendChild(toast);

  // Remove toast after 3 seconds
  // 实现动态删除 缓慢删除
  toast.classList.add("toast-show");

  setTimeout(() => {
    toast.remove();
  }, removeTimeout);
};

export default toast;
// export { toast };
